package com.wthink.hzgj.util

object CmdUtil {

    private val mEnter = "\n".toByteArray()

    fun exec(cmd: String) {
        try {
//            val proc = Runtime.getRuntime().exec("/system/xbin/su")
            val pb = ProcessBuilder("sh")
            pb.redirectErrorStream(true)
            val proc = pb.start()

            proc.outputStream.write("su".toByteArray())
            proc.outputStream.write(mEnter)
            
            proc.outputStream.write(cmd.toByteArray())
            proc.outputStream.write(mEnter)
            proc.outputStream.flush()
            proc.outputStream.close()
            val ret = proc.waitFor()
            println(String(proc.inputStream.readBytes()))
            println("ret:${ret}")
        } catch (err: Throwable) {
            err.printStackTrace()
        }
    }

}